//
//  ViewController.m
//  simple
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)NSMutableArray *array;//名称
@property(strong,nonatomic)NSMutableArray *array2;//图片
@property(strong,nonatomic)NSMutableArray *array3;//文字
@property(strong,nonatomic)NSMutableDictionary *diction;
@property(strong,nonatomic)NSArray *ListArray;//文件取出数组
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *path=[[NSBundle mainBundle]pathForResource:@"heroes" ofType:@"plist"];
    self.ListArray =[NSArray arrayWithContentsOfFile:path] ;
   self.diction=self.ListArray[0];
    self.array=[NSMutableArray array];
    self.array2=[NSMutableArray array];
    self.array3=[NSMutableArray array];
    for (int i =0; i<self.ListArray.count; i++) {
        self.diction=self.ListArray[i];
        [self.array addObject:self.diction[@"name"]] ;
        [self.array2 addObject:self.diction[@"icon"]] ;
         [self.array3 addObject:self.diction[@"intro"]] ;
    }

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//有几段
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"表格:有几段?");
    return 1;
}
// 有几行？
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"表格:有几行?");
    return self.array.count;
}

// 第几段第几行的单元格内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"表格:第%i行是什么内容?",indexPath.row);
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    
    //UITableViewCell的三个默认属性:
    // 1. 文本标签 textLabel
    cell.textLabel.text = self.array[indexPath.row];
    // 2. imageView
  
    cell.imageView.image = [UIImage imageNamed:self.array2[indexPath.row]];
    
    // 3. detailLabel
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.array3[indexPath.row]];
    
    // 默认样式
    //    UITableViewCellStyleDefault,	// Simple cell with text label and optional image view (behavior of UITableViewCell in iPhoneOS 2.x)
    // 带副标题样式1
    //    UITableViewCellStyleValue1,		// Left aligned label on left and right aligned label on right with blue text (Used in Settings)
    // 带副标题样式2
    //    UITableViewCellStyleValue2,		// Right aligned label on left with blue text and left aligned label on right (Used in Phone/Contacts)
    // 带副标题样式3
    //    UITableViewCellStyleSubtitle	// Left aligned label on top and left aligned label on bottom with gray text (Used in iPod).
    
    return cell;
}
#pragma mark - 为表格提供事件处理
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:self.array[row] message:self.array3[row] delegate:nil cancelButtonTitle:@"离开" otherButtonTitles: nil];
    [alert show];
}




@end
